//
//  XianhuoModel.swift
//  YunshuApp
//
//  Created by 周文杰 on 2017/5/6.
//  Copyright © 2017年 zwj. All rights reserved.
//

import UIKit
import HandyJSON

class XianhuoModel: NSObject,HandyJSON {

    var xianhuoId = ""
    var type = 0 //0 现货 1采购
    var contact = ""
    var typepic  = ""
    var createtime  = ""
    var updatetime = ""
    var place = ""
    var number = ""
    var company = ""
    var tel = ""
    var mark = "" //备注
    var channelname = ""
    var ext = ""
    var kucunpic = ""
    
    var factory = ""//工厂名字
    
    var price = ""
    
    var specification = ""//规格
    
    var quality = ""//材质
    
    var productname = ""
    
    var storehouse = ""
    
    var companymark = ""
    
    var companylink = ""
    
    var productpic = ""
    var productpic1 = ""
    var productpic2 = ""
    
    var userid = ""
    
    var audit = "0"
    var auditdesc = ""
    var advert=""
    
    required override init() {
        
    }
    
    func mapping(mapper: HelpingMapper) {
        mapper.specify(property:&xianhuoId, name: "id")
        mapper.specify(property:&contact, name: "name")
        mapper.specify(property:&factory,name: "productcompany")
        mapper.specify(property:&specification,name: "spec")
        mapper.specify(property:&quality,name: "material")
        mapper.specify(property:&storehouse,name: "productplace")

    }
    
    func getDate() -> String {
        let millionSeconds:Double = Double(self.updatetime)!
        let date2 = Date.init(timeIntervalSince1970: TimeInterval( millionSeconds/1000) )
        let formatter = DateFormatter.init()
        formatter.dateFormat = "YYYY-MM-dd HH:mm"
        return formatter.string(from: date2)
    }
    
    func serialize() -> [String:Any] {
        
//        let serialized = JSONSerializer.serialize(model: self)
        var result = self.toJSON() ?? [:] //serialized.toSimpleDictionary()!
        result.removeValue(forKey: "id")
//        result["name"] = result["contact"]
//        result.removeValue(forKey: "contact")
//
//        result["productcompany"] = result["factory"]
//        result.removeValue(forKey: "factory")
        
//        result["material"] = result["quality"]
//        result.removeValue(forKey: "quality")
        
//        result["spec"] = result["specification"]
//        result.removeValue(forKey: "specification")
        
//        result["productplace"] = result["storehouse"]
//        result.removeValue(forKey: "storehouse")
        return result;
    }
    
    func serialize2() -> [String:Any] {
        
        let result = self.toJSON() ?? [:] 
        return result;
    }
    
}
